// pages/stock/stock.js
var app = getApp()
Page({
  data: {
  	morPrice:"",
    morId:'',
  	aftPrice:"",
    aftId:'',
  	free:"0",
  	time:"",
  	price:'',
  	choose:'free',
    laborItem:''
  },
  onLoad: function (options) {
    // const page = getCurrentPages()
    // let prevPage  = page[pages.length - 2]
    // prevPage.setData({
    // 	peoplePrice:this.data.price
    // })
    app.getMemInfo().then(res=>{
      let agentId = res.data.agentId
      this.getLaborCost(1)
    })
  },
  bindNavToSet(){
  	wx.navigateTo({
  		url:'../my/set/feeSet/feeSet'
  	})
  },
  priceCalc(){

  },
  chosePeoplePrice(e){
  	console.log(e.currentTarget.dataset)
  	this.setData({
  		choose:e.currentTarget.id,
  		price:e.currentTarget.dataset,
  	})
  },
  inputTime(e){
  	this.setData({
  		time:e.detail.value
  	})
  },
  regInput(e){
  	var reg = /^(\-)?\d+(\.\d{1,2})?$/
  	let test = reg.test(e.detail.value)
  	console.log(test)
  	if (!test) {
  		this.setData({
  			time:'0'
  		})
  		app.errorMsg('请输入正确的时长')
  	}
  },
  getLaborCost(agentId){
    var that = this
    var data = {
      agentId
    }
  	app.request('wx_app/cost/labor/list',data,'GET').then(res=>{
  		console.log(res.data.labor_cost_list)
      that.setData({
        morPrice:res.data.labor_cost_list[0].price,
        morId:res.data.labor_cost_list[0].id,
        aftPrice:res.data.labor_cost_list[1].price,
        aftId:res.data.labor_cost_list[1].id
      })
  	})
  },
  confirm(){
  	var that = this
  	var page = getCurrentPages()
  	var prevPage = page[page.length-2]
    var free = {
      id:0,
      price:0
    }
  	prevPage.setData({
  		peoplePrice:that.data.price==""?0:that.data.price.price*that.data.time,
      laborCostTime:that.data.time==""?0:that.data.time,
      laborItem:that.data.price==""?free:that.data.price
  	})
  	wx.navigateBack()
  }
})